package reflect;

import java.lang.reflect.Field;

public class ReflectDemo9 {
    public static void main(String[] args) throws Exception {
        Person person = new Person("张三",20);
        System.out.println(person);
        Class cls = person.getClass();//获取person对象的的类对象
        Field fie=cls.getDeclaredField("age");//获取类对象的属性age
        fie.setAccessible(true);//更改属性权限
        fie.set(person,30);//更改age属性值
        int age=(Integer)fie.get(person);
        System.out.println(age);
        fie.setAccessible(false);
        System.out.println(person);
    }
}
